#include "editwidget.h"
#include "ui_dialogConfigParam.h"
#include "globals.h"

#include <QStringList>



CEditWidget::CEditWidget(QDialog *parent) :
    QDialog(parent),
    dia(new Ui::DialogEditParam)
{
    for (int i=0;i<6; i++)
    {
	QDoubleValidator *v= new QDoubleValidator(this);
	v->setDecimals(4);
	validators[i] = v;
    }
    dia->setupUi(this);
    dia->lineLowCrit->setValidator(validators[0]);
    dia->lineLowWarn->setValidator(validators[1]);
    dia->lineLowColor->setValidator(validators[2]);

    dia->lineHiColor->setValidator(validators[3]);
    dia->lineHiWarn->setValidator(validators[4]);
    dia->lineHiCrit->setValidator(validators[5]);
    setModal(true);

    model = new QStringListModel(this);
    dia->listViewAvail->setModel(model);

    localModel = new QStringListModel(this);
    dia->listViewRecip->setModel(localModel);
}

CEditWidget::~CEditWidget()
{
    delete dia;
    for (int i=0; i<6; i++) delete validators[i];
    delete model;
};

void CEditWidget::show(CTechParameter *param)
{   
    dia->labelParamName->setText(param->getName());
    /*dia->listViewAvail->selectAll();
    dia->listViewAvail->clearSelection();*/
    QStringList globalStrings;
    QStringList localStrings;
   /* for(int i=0;i<globals->env()->getRecipientsCount();i++)
    {
        CRecipient* rec = globals->env()->getRecipient(i);
	{
	    QString res = rec->name + "("+rec->phone+")";
	    CRecipient *rl;
	    bool found =false;
	    for (unsigned int j =0; j< param->recipients.size(); j++)
	    {
		rl = param->recipients[j];
		if (rl->name == rec->name  && rl->phone == rec->phone)
		{
		    localStrings << res;
		    found = true;
		    break;
		}
	    }

	    if (found) found = false;
	    else
	    {
		globalStrings << res;
	    }

	}



    }*/

    model->setStringList(globalStrings);
    localModel->setStringList(localStrings);

    QDialog::show();
};
